package com.itzg.vboxfarm.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

@Entity
public class HostMachine implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	private long id;
	
	@Version
	private int version;
	
	@ManyToOne
	private Site site;
	
	private String hostname;
	
	/** Web service port. Default is 18083 */
	private int wsPort = 18083;
	
	private String wsUsername = "";
	
	private String wsPassword = "";
	
	@Column(nullable=true)
	private Long processors;
	
	@Column(nullable=true)
	private Long totalMemory;
	
	@Enumerated(EnumType.STRING)
	private ConnectionStatus connectionStatus = ConnectionStatus.UNKNOWN;
	
	private String statusMessage;

	public HostMachine(String hostname) {
		this.hostname = hostname;
	}
	
	public HostMachine() {
	}

	@Override
	public String toString() {
		return "HostMachine:[id="+id+",hostname="+hostname+"]";
	}
	
	@Override
	public int hashCode() {
		return (int) id;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) return false;
		if (obj == this) return true;
		HostMachine rhs = (HostMachine) obj;
		return rhs.id == this.id;
	}

	public String getHostname() {
		return hostname;
	}

	public void setHostname(String hostname) {
		this.hostname = hostname;
	}

	public int getWsPort() {
		return wsPort;
	}

	public void setWsPort(int wsPort) {
		this.wsPort = wsPort;
	}

	public String getWsUsername() {
		return wsUsername;
	}

	public void setWsUsername(String wsUsername) {
		this.wsUsername = wsUsername;
	}

	public String getWsPassword() {
		return wsPassword;
	}

	public void setWsPassword(String wsPassword) {
		this.wsPassword = wsPassword;
	}

	public long getId() {
		return id;
	}

	public ConnectionStatus getConnectionStatus() {
		return connectionStatus;
	}

	public void setConnectionStatus(ConnectionStatus connectionStatus) {
		this.connectionStatus = connectionStatus;
	}

	public int getVersion() {
		return version;
	}

	public Site getSite() {
		return site;
	}

	public void setSite(Site site) {
		this.site = site;
	}

	public String getStatusMessage() {
		return statusMessage;
	}

	public void setStatusMessage(String statusMessage) {
		this.statusMessage = statusMessage;
	}

	public Long getProcessors() {
		return processors;
	}

	public void setProcessors(Long processors) {
		this.processors = processors;
	}

	public Long getTotalMemory() {
		return totalMemory;
	}

	public void setTotalMemory(Long totalMemory) {
		this.totalMemory = totalMemory;
	}
}
